package com.wtwd.device.controller;

import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.vo.UploadFileVO;
import com.wtwd.device.service.FileService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * Created by mjy on 2023/8/17 10:04
 */

@Api(tags = "文件服务")
@RestController
@RequestMapping("/file-service")
public class FileController {

    @Resource
    private FileService fileService;


    /**
     *
     * @param file
     * @param type
     * @return
     */
    @ApiOperation(value = "文件上传", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", value = "文件", required = true, dataTypeClass = MultipartFile.class)
            , @ApiImplicitParam(name = "type", value = "文件类型 1:类型名称国际化文件 2.文本内容国际化文件,3.健康类型图标", dataType = "int", required = false)
    })
    @ApiResponses({@ApiResponse(code = 400, message = "参数错误")
    })
    @PostMapping("/uploadFile")
    private ResultVO uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("type") Integer type) {
        UploadFileVO uploadFileVO;
        try {
            uploadFileVO = fileService.uploadFile(file, type);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.error();
        }
        return ResultVO.success(RespCode.SUCCESS, uploadFileVO);
    }


}
